package com.atguigu.gmall.mq.consumer;

import com.atguigu.gmall.mq.config.DelayedMqConfig;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author: 李旭
 * @Time: 15:34
 * @Description:
 */
@Component
public class DelayedConsumer {

    //接收消息
    @RabbitListener(queues = DelayedMqConfig.queue_delay_1)
    public void delayMessage(String msg, Message message, Channel channel){
        try {
            System.out.println("delayMessage接收的消息：" + msg);
            System.out.println("delayMessage接收的时间：" + new Date());
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
